package com.michael;

import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2019/3/17 0017.
 */
public class PaymentFactory {

    private static final String ALI_PAY = "AliPay";
    private static final String WECHAT_PAY = "WeChatPay";
    private static final String JD_PAY = "JDPAY";
    private static final String DEFAULT_PAY = ALI_PAY;

    private static Map<String,Payment> map = new HashMap<>();

    static {
        map.put(ALI_PAY,new AliPay());
        map.put(WECHAT_PAY,new WechatPay());
        map.put(JD_PAY,new JDPay());
        map.put(DEFAULT_PAY,new AliPay());
    }

    public static Payment pay(String payKey){
        if (!StringUtils.isEmpty(payKey) && map.containsKey(payKey))
            return map.get(payKey);
        return map.get(DEFAULT_PAY);
    }
}
